package com.service.web;

import java.io.Serializable;
import java.util.Map;

import javax.faces.application.FacesMessage;
import javax.faces.application.FacesMessage.Severity;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ComponentSystemEvent;

@ManagedBean(name="growCtrl")
public class MessageUtil implements Serializable{

	private static final long serialVersionUID = 1L;

	public void renderMessage(String message, Severity severity){
		FacesContext context = FacesContext.getCurrentInstance();
		FacesMessage facesMessage = new FacesMessage(severity, message, null);
		context.addMessage(null, facesMessage);
	}
	
	public void preRender(ComponentSystemEvent cse) throws AbortProcessingException {
        Map<String, Object> atributos = cse.getComponent().getAttributes();
        String error = (String)atributos.get("error");
        if (error != null && !"".equals(error)) {
            FacesContext facesContext = FacesContext.getCurrentInstance();
            facesContext.addMessage("", new FacesMessage(error));
        }
    }
	
}
